import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import find_peaks

if __name__ == "__main__":

    # 示例信号
    np_arr = np.array([0, 1, 2, 1, 0, 1, 4, 1, 0, 1, 2, 1, 0])

    # 不同的 prominence 值
    prominence_values = [0.5, 2, 3]

    plt.figure(figsize=(14, 8))

    for i, prominence in enumerate(prominence_values, 1):
        peaks, properties = find_peaks(np_arr, prominence=prominence)
        plt.subplot(1, 3, i)
        plt.plot(np_arr)
        plt.plot(peaks, np_arr[peaks], "x")
        plt.title(f'Prominence = {prominence}')
        plt.xlabel('Sample number')
        plt.ylabel('Signal amplitude')

    plt.tight_layout()
    plt.show()